//
//  ZTTabBarController.m
//  项目练习
//
//  Created by 张江涛 on 15/11/29.
//  Copyright © 2015年 张江涛. All rights reserved.
//

#import "ZTTabBarController.h"
#import "ZTAttentionViewController.h"
#import "ZTEssenceViewController.h"
#import "ZTMEViewController.h"
#import "ZTNewViewController.h"
#import "ZTTabBar.h"
#import "ZTNavigationController.h"
@interface ZTTabBarController ()

@end

@implementation ZTTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    //添加所有控制器
    [self setControllers];
    
    //统一这是字体
    [self setupItemTitleteTextAttrs];
    
    //将系统的tabBar变为自己的tabBar
    [self setTabBar];

    
}

//将系统的tabBar变为自己的tabBar
- (void)setTabBar
{
    [self setValue:[[ZTTabBar alloc]init ] forKeyPath:@"tabBar"];
}




//添加子控制器 包装导航控制器
- (void)setControllers


{
    
    [self setOneChildVc:[[ZTNavigationController alloc]initWithRootViewController:[[ZTEssenceViewController alloc]init ] ] title:@"精华" image:@"tabBar_essence_icon" seletedImage:@"tabBar_essence_click_icon"];
    
    [self setOneChildVc:[[ZTNavigationController alloc]initWithRootViewController:[[ZTNewViewController alloc]init ] ] title:@"新帖" image:@"tabBar_new_icon" seletedImage:@"tabBar_new_click_icon"];
    
    [self setOneChildVc:[[ZTNavigationController alloc]initWithRootViewController:[[ZTAttentionViewController alloc]init ] ] title:@"关注" image:@"tabBar_friendTrends_icon" seletedImage:@"tabBar_friendTrends_click_icon"];
    
    [self setOneChildVc:[[ZTNavigationController alloc]initWithRootViewController:[[ZTMEViewController alloc] init] ] title:@"我的" image:@"tabBar_me_icon" seletedImage:@"tabBar_me_click_icon"];
    
    
    
    
}


//设置一个控制器
- (void)setOneChildVc:(UIViewController *)ChildVc  title:(NSString *)title image:(NSString *)image seletedImage:(NSString *)seletedImage
{
    ChildVc.tabBarItem.title = title;
    if (image.length) ChildVc.tabBarItem.image = [UIImage imageNamed:image];
    if (seletedImage.length) ChildVc.tabBarItem.selectedImage  = [UIImage imageNamed:seletedImage];
    
    [self addChildViewController:ChildVc];
}



/**
 *  设置字体
 */
- (void)setupItemTitleteTextAttrs
{
    
    //设置默认状态下文字的属性
    NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
    normalAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    normalAttrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    
    //设置选中状态下的文字属性
    NSMutableDictionary *seletedAttrs = [NSMutableDictionary dictionary];
    seletedAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    
    //利用Appearance来统一设置  方法参数是个字典,所以需要创建字典
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
    [item  setTitleTextAttributes:seletedAttrs forState:UIControlStateSelected];
    }





@end
